package com.sky.mapper;

import com.sky.autofill.AutoFill;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * @param username
     * @return {@link Integer}
     */
    @Select("select count(*) from employee where username = #{username}")
    Integer selectCount(String username);

    /**
     * @param employee
     */
    @AutoFill(OperationType.INSERT)
    void insert(Employee employee);

    /**
     * @param name
     * @return {@link List}<{@link Employee}>
     */
    List<Employee> selectListByName(String name);

    /**
     * @param id
     * @return {@link Employee}
     */
    @Select("select * from employee where id = #{id}")
    Employee selectById(Long id);

    /**
     * @param employee
     */
    @AutoFill(OperationType.UPDATE)
    void update(Employee employee);
@Select("select count(*) from employee where username = #{username} and id != #{id};")
    Integer selectCountByUsernameNotSelf(String username, Long id);
}
